<%@ page language="java" import="com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<html:html>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>

<script language='javascript'>

	function searchCostCodes()
	{
		document.costCodeSetupForm.action = '<%=chipTracContext%>/costCodeSetup.do?action=search';
        document.costCodeSetupForm.submit();
    }

    function isDuplicatesPresent(emails)
    {
        if (emails.length == null)
        {
            return false;
        }
        for (i = 0; i < emails.length; i++)
        {
            var cnt = 0;
            var email = trim(emails[i].value)
            if (email != '')
            {
                for (j = 0; j < emails.length; j++)
                {
                    var email2 = trim(emails[j].value)
                    if (email.toUpperCase() == email2.toUpperCase())
                    {
                        cnt = cnt + 1;
                    }
                    if (cnt > 1)
                    {
                        emails[i].select();
                        emails[i].focus();
                        return true;
                    }
                }
            }
        }
        return false;
    }

    function checkEmail( email )
    {           
        if (email.length != null)
        {
            for (var k = 0; k < email.length; k++)
            {

                if ( email[k].value.trim() != '' && !isValidEMailId( email[k] ) )
                {
                    email[k].focus();
                    email[k].select();
                    return false;
                }
            }
        }
        else
        {
            if( email.value.trim() != '' && !isValidEMailId (email) )
            {
                email.focus();
                email.select();
                return false;
            }
        }
        return true;
    }
    function uploadFile()
    {
        var pa = document.getElementById("errors");
        pa.innerHTML = '';
        if (document.costCodeSetupForm.theFile.value == '')
        {
            pa.innerHTML = '<li>Please select a file to upload</li>';
            document.costCodeSetupForm.theFile.focus();
            return;
        }

        if (document.costCodeSetupForm.scheduleDate.value == '')
        {
            pa.innerHTML = '<li>Please select Date to Schedule the update</li>';
            return;
        }
        else if (document.costCodeSetupForm.scheduleDate.value != "")
        {
            if (chkDate(document.costCodeSetupForm.scheduleDate.value, 'Schedule Date ', 'Y') == false)
            {
                pa.innerHTML = errMsg;
                document.costCodeSetupForm.scheduleDate.focus();
                return;
            }
        }

        if (document.costCodeSetupForm.emails != null)
        {
            var isEmailInvalid = !checkEmail(document.costCodeSetupForm.emails);
            if (isEmailInvalid)
            {
                pa.innerHTML = "<li> Please enter valid Email</li> ";
                return;
            }
            else
            {
                if (isDuplicatesPresent(document.costCodeSetupForm.emails))
                {
                    pa.innerHTML = "<li>Job Notification Emails has Duplicates</li>"
                    return;
                }
            }
        }

        document.costCodeSetupForm.action = '<%=chipTracContext%>/costCodeSetup.do?action=upload';
		document.costCodeSetupForm.submit();
     }

	function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }
    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }

function addMore()
{
        var tab = document.getElementById ("costCodeScheduleJobTable");
        var index = tab.rows.length;
        var newRow = tab.insertRow ( index - 1  );

        var newCell1 = newRow.insertCell();
        var newCell2 = newRow.insertCell();
        newCell1.align = "right";
        newCell1.width = "20%";
        newCell2.align = "left";
        newCell2.width = "20%";

        var htmltext = '<input type="text" name="emails" size=35 class="txfield">';
        newCell1.innerHTML = '';
        newCell2.innerHTML = htmltext;

}

</script>

<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

	<!-- Side Navigation start -->
	<%@ include file="/jsp/finance/finance_menu.jsp" %>
	<!-- end of the side navigations -->
     </TD>
	<TD bgcolor="#ffffff">
        <IMG height="9" src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></TD>
        <TD bgcolor="#ffffff"><IMG height=460 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="2"></TD>
        <TD valign="top" width="100%">
        <IMG height="1" src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width="500" border="0">
        <BR>
	<html:form name="costCodeSetupForm" type="com.scalar.chiptrack.finance.forms.CostCodeSetupForm"  enctype="multipart/form-data" action="/costCodeSetup.do">
            
    <table border="0" width="100%" align="center">
        <TR><TD colspan="4" class="NArialW" align="center">Cost File Upload</TD></TR>
        <tr><td align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></td></tr>
		<tr><td colspan='4' align="center"><chiptrack:errors styleClass='NArialL'/></td></tr>
        <tr><td colspan='4' align="center"><chiptrack:info styleClass='NArialL'/></td></tr>
	    <tr><td><img height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
     <tr>
        <td class='NArialL' align="center"> Upload File:&nbsp;&nbsp; <html:file styleClass="txfield" property="theFile"></html:file>
            &nbsp;&nbsp;&nbsp;&nbsp;
		</td>
		</tr>
        <tr>
			<td width="20%" align="center" class="NArialL">
            <input type="radio" name="fileType" value="unitCostFile" checked>
    	        UnitCost File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="fileType" value="costCodeFile">
    	        costCode File
            </td>
		</tr>
			<tr><td><IMG height=40 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></td></tr>
		<tr>
			<td class='NArialL' align="center"><font class="NArialL">Please Schedule the job to Update Cost information</font></td>
		</tr>

		<tr>
			<td>
				<table border="0" width="100%" align="center" id = "costCodeScheduleJobTable" >
					<tr>
						<td width="20%" align='Right'><font class="NArialL">Schedule Date<font color=red>*</font>:&nbsp;</font></td>
						<td width="20%" align='left'><html:text name="costCodeSetupForm" property="scheduleDate" size="15" styleClass="txfield" />
						<a href="javascript:openCalendar(document.costCodeSetupForm.scheduleDate)"><img onmouseover="window.status='Click to Select Date';return true" title="Click here to Select Date" onmouseout="window.status='';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
						</td>
					</tr>
					<tr>
						<td width="20%" align='Right'><font class="NArialL">Schedule Time<font color=red>*</font>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
						<td width="20%" align='left'>
							<html:select name="costCodeSetupForm" property="scheduleTime" styleClass="txfield">
								<html:options collection="hoursList" property="value" labelProperty="label"/>
							</html:select>
							<html:select name="costCodeSetupForm" property="scheduleMinute" styleClass="txfield">
								<html:options collection="minutesList" property="value" labelProperty="label"/>
							</html:select>
 							<html:select name="costCodeSetupForm" property="am_pm" styleClass="txfield">
								<html:options collection="ampmList" property="value" labelProperty="label"/>
							</html:select>
						</td>
					</tr>
					<tr>
						<td width="20%" align='Right'>
							<font class="NArialL">Email Notification:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
						</td>
						<td width="20%" align='left'>
                            <logic:present name="costCodeSetupForm" property="emails" >
                            <logic:iterate name="costCodeSetupForm" id="email" property="emails" type="java.lang.String">
                                 <input type = "text" name = "emails" class="txfield" size = "35" value = "<%=email%>" ><br>
                            </logic:iterate>
                            </logic:present>
                            <logic:notPresent name="costCodeSetupForm" property="emails" >
                             <html:text name="costCodeSetupForm" property="emails" size = "35" styleClass="txfield"/>
                            </logic:notPresent>
                        </td>
					</tr>

                    <tr>
                        <td width="20%" align='Right'>
                    </td>
                    <TD width="20%" align=center><a href="javascript:addMore();"><img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border="0" onmouseover="window.status='Click to Add Notification mail';return true" onmouseout="window.status='';return true" title="Click here to Notification mail"/></a></TD>
										
					</tr>

                </table>
			</td>
		</tr>
		<tr><TD bgcolor="#ffffff"><IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD></tr>
		<tr><td align="center"><a href="javascript:uploadFile()"><img border="0" align ="center" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="56" height="18" onMouseOver="window.status='Click to upload the File';return true" onmouseout="window.status='';return true" title="Click here to upload the File"></a>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:document.costCodeSetupForm.reset();"><img border="0" align ="center" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" onMouseOver="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a></td>
		</tr>
      </table>
     </html:form>
    </TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</html:html>